package com.richie696.connect;

import com.richie696.catalina.LifecycleException;
import com.richie696.connect.http11.Http11BioProtocol;
import com.richie696.connect.http11.Http11NioProtocol;

import java.util.Arrays;

public enum ProtocolType {

    HTTP11_NIO("HTTP/1.1 NIO", Http11NioProtocol.class),

    HTTP11_BIO("HTTP/1.1 BIO", Http11BioProtocol.class);

    private final String name;
    private final Class<? extends ProtocolHandler> className;
    ProtocolType(String name, Class<? extends ProtocolHandler> className) {
        this.name = name;
        this.className = className;
    }

    public String getName() {
        return name;
    }

    public Class<? extends ProtocolHandler> getClassName() {
        return className;
    }

    public static ProtocolType nameOf(String name) throws LifecycleException {
        return Arrays.stream(values()).filter(o -> o.name.equals(name)).findFirst().orElseThrow(LifecycleException::new);
    }

}
